//
//  CYDefaultRecordCell.m
//  CreditAddressBook
//
//  Created by Lee on 15/5/8.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

#import "CYDefaultRecordCell.h"
#import "CYDefaultRecordAO.h"
#import "UIImageView+WebCache.h"
#import "CYURL.h"
#import "CYCreditTool.h"
#import "NSString+Extension.h"

@interface CYDefaultRecordCell ()

@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *idCardLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *publicDate;
@end

@implementation CYDefaultRecordCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *ID = @"newCell";
    CYDefaultRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CYDefaultRecordCell" owner:nil options:nil] lastObject];
    }
    return cell;
}

- (void)setDefr:(CYDefaultRecordAO *)defr {
    _defr = defr;
    if (defr.headPic) {
        [self.headImageView sd_setImageWithURL:[NSURL URLWithString:[CYUSERIMAGEBASIC stringByAppendingString:defr.headPic]] placeholderImage:[UIImage imageNamed:@"putao_icon_quick_replace_s"]];
    }
    
    self.headImageView.layer.cornerRadius = 4;
    self.headImageView.layer.masksToBounds = YES;
    self.nameLabel.text = [NSString stringWithFormat:@"违约人:%@", defr.name];
    self.idCardLabel.text = [NSString stringWithFormat:@"身份证号:%@", defr.certificateNo];
     if (defr.phone && defr.phone.length>=10) {
         NSString *phonefont = [defr.phone substringToIndex:5];//截取掉下标5之后的字符串
          NSString *phonebehiend = [defr.phone substringFromIndex:7];//截取掉下标7之前的字符串
          self.phoneLabel.text = [NSString stringWithFormat:@"电话号码:%@**%@", phonefont,phonebehiend];

     }else{
           self.phoneLabel.text = @"电话号码:--";
     }
        self.typeLabel.text = [NSString stringWithFormat:@"数据来源:%@", defr.typeName];
    if (defr.createTime && !defr.createTime.isEmpty) {
        NSString *publicDate = [CYCreditTool timewithLongLongValue:defr.createTime.longLongValue formatter:@"yyyy-MM-dd"];
        self.publicDate.text = CYStringFormat(@"发布时间:%@", publicDate);
    } else {
        self.publicDate.text = @"发布时间:无";
    }
    if (defr.iconTag == 1) {
        [self.iconImageView setImage:[UIImage imageNamed:@"yellow"]];
//        self.iconLabel.text = @"违约小于90天";
    }else if (defr.iconTag == 0) {
        [self.iconImageView setImage:[UIImage imageNamed:@"orange"]];
//        self.iconLabel.text = @"违约大于90天";
    }else {
        [self.iconImageView setImage:[UIImage imageNamed:@"red"]];
//        self.iconLabel.text = @"违约大于180天";
    }
}

- (UIEdgeInsets)layoutMargins {
    return UIEdgeInsetsZero;
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
